<template>
  <div class="cgdsmore">
    <van-tabs v-model="active">
      <van-tab title="全部"></van-tab>
      <van-tab title="进行中"></van-tab>
      <van-tab title="未开始"></van-tab>
      <van-tab title="已结束"></van-tab>
    </van-tabs>
    <van-list ref="vanList" v-model="loading" :finished="finished" :finished-text="finishedText" @load="onLoad" :immediate-check="false">
      <template v-for="(item,index) in list">
        <cgds-item :key="index" :item="item" />
      </template>
      <empty v-if="isEmpty" />
    </van-list>
  </div>
</template>
<script>
import CgdsItem from '@/components/CgdsItem.vue';
import { F700107 } from '@/service/api.js';
import Empty from "@/components/Empty.vue";
export default {
  name: "Cgdsmore",
  components: {
    CgdsItem,
    Empty
  },
  data () {
    return {
      finishedText: "没有更多了",
      isEmpty: false,
      active: 0,
      list: [],
      loading: false,
      finished: false,
      size: 15,
      page: 0,
      now_status: '' // 0-未开始 1-进行中 2-已结束
    }
  },
  watch: {
    active (cur, old) {
      debugger
      this.page = 0;
      this.list = [];
      this.finished = false;
      this.isEmpty = false;
      switch (cur) {
        case 0:
          this.now_status = '';
          this.$refs.vanList.check();
          break;
        case 1:
          this.now_status = '1';
          this.$refs.vanList.check();
          break;
        case 2:
          this.now_status = '0';
          this.$refs.vanList.check();
          break;
        case 3:
          this.now_status = '2'
          this.$refs.vanList.check();
          break;
        default:
          break;
      }
    }
  },
  mounted () {
    this.init();
  },
  //初始化生命周期，调用init
  methods: {
    init () {
      setTimeout(() => {
        // 这里是异步操作
        console.log(11111)
      }, 2000)
      console.log(2222)
      this.$refs.vanList.check();
    },
    onLoad () {
      this.page++;
      this.F700107();
    },
    // 获取炒股大赛数据
    async F700107 () {
      let res = await F700107({
        channel_type: "2",
        act_type_subset: "15",
        now_status: this.now_status,
        act_type: "0",
        page: this.page,
        size: this.size
      });
      if (res.data.code === 0) {

        this.loading = false;
        let list = res.data.data.data || [];

        // 第一页加载为空数据的时候
        if (this.page === 1 && list.length === 0) {
          this.isEmpty = true;
          this.finished = true;
          this.finishedText = "";
          return false;
        }

        // 加载到最后一页
        if (list.length < this.size) {
          this.list = this.list.concat(list);
          this.finished = true;
          this.finishedText = "没有更多了";
          return false;
        }

        this.list = this.list.concat(list);
        return res;
      }
    }
  }
}
</script>
<style lang="scss">
.cgdsmore {
  background-color: #fff;
  min-height: 100vh;
}
</style>


